package CH9;

import javax.swing.*;
import java.awt.*;

/**
 * @author: LiuBoTao
 * @date: 2022/10/13
 * @ApiNote
 */
public class GuiDemo1 {
    public static void main(String[] args) {
        JFrame f=new JFrame("Liubotao");
        f.setBounds(100,90,400,800);
        f.setResizable(true);//设置窗口是否可调整大小
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//设置窗体行为：用户单击关闭按钮时，窗体关闭了

         FlowLayout flow=new FlowLayout();/**/
        /* flow.setAlignment(FlowLayout.LEFT);
        GridLayout*/
        /*GridBagLayout flow=new GridBagLayout(8,7);*/
        f.setLayout(flow);

        GridBagConstraints constraints=new GridBagConstraints();

        JLabel label=new JLabel("用户名：");
        f.add(label);
        JTextField text=new JTextField("aaaaaa");
        text.setText("奥斯卡冷冻机房看拉时代峻峰辣椒水两地分居拉伸了");
        System.out.println(text.getText());
        f.add(text);

        JLabel label2=new JLabel("密码：");
        f.add(label2);
        JPasswordField pwd=new JPasswordField("bbb");
        pwd.setEchoChar('*');
        System.out.println(pwd.getText());
        System.out.println(pwd.getPassword());
        f.add(pwd);

        JComboBox comboBox=new JComboBox();
        comboBox.addItem("男");//0--->1
        comboBox.addItem("女");//1--->2
        comboBox.insertItemAt("保密",0);//0
         comboBox.setSelectedItem("女");/**/
         comboBox.setSelectedIndex(0);/**/
        f.add(comboBox);

        JButton  buttonOK=new JButton("确定");
        f.add(buttonOK);
        JButton  buttonCancel=new JButton("取消");
        f.add(buttonCancel);

        //  f.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);//设置窗体行为：用户单击关闭按钮时，窗体啥都不干
         f.setVisible(true);//设置窗口为可见，默认不可见/**/

    }
}
